<?php

/**
* alltosun.com  promotion.php for newbd
* ============================================================================
* 版权所有 (C) 2009-2014 北京互动阳光科技有限公司，并保留所有权利。
* 网站地址: http://www.alltosun.com
* ----------------------------------------------------------------------------
* 许可声明: 这是一个开源程序，未经许可不得将本软件的整体或任何部分用于商业用途及再发布。
* ============================================================================
* Author: 吴松键 (wusj@alltosun.com)
* Date: 15/1/21 下午4:11
*/

class promotion_widget
{
    private $per_page = 10;
    private $page_no   = 1;

    public function get_list($params = array())
    {
        if (isset($params['per_page']) && $params['per_page']) {
            $this->per_page = $params['per_page'];
        }
        if (isset($params['page_no']) && $params['page_no']) {
            $this->page_no = $params['page_no'];
        }
        if (isset($params['title']) && $params['title']) {
            $goods_filter['`title` LIKE '] = '%'.$params['title'].'%';
            $filter['goods_id'] = _model('goods')->getFields('id', $goods_filter);
        }
        if (isset($params['status']) && $params['status']) {
            $filter['status'] = $params['status'];
        } else {
            $filter['status'] = 1;
        }

        $count = _model('promotion_add')->getTotal($filter);
        $list  = array();
        if ($count) {
            $pager = new Pager($this->per_page);
            if ($pager->generate($goods_count)) {
                Response::assign('pager', $pager);
            }
            $order = ' ORDER BY `add_time` DESC ';

            $list = _model('promotion_add')->getList($filter, $order.$pager->getLimit($this->page_no));
            foreach ($list as $k=>$v) {
                $goods_info = _uri('goods', $v['goods_id']);
                $list[$k]['price'] = $goods_info['price'];
                $list[$k]['title'] = $goods_info['title'];
                $list[$k]['cover'] = goods_helper::get_goods_cover($v['goods_id']);
            }
        }

        return $list;
    }
}